<?php
class table_user_user extends common_table{
	public function __construct(){
		$this->_pk='uid';
		$this->_table='user_user';
		parent::__construct();
	}
	public function fetch_by_uid($uid){
		$uid=intval($uid);
		if(!empty($uid) && $uid!=0){
			return DB::fetch_first('SELECT * FROM %t WHERE uid=%d',array($this->_table,$uid));
		}
		return false;
	}
	public function fetch_by_username($username){
		if(!empty($username) && $username){
			return DB::fetch_first('SELECT * FROM %t WHERE username=%s',array($this->_table,$username));
		}
		return false;
	}
	public function login_update($username){//更新登录的user表
		if(!empty($username)){
			$data=array();
		    $data['lasttime']=date("Y-M-d,H:i:s");
		    $data['location']="";//登录位置
		    $condition="username='".$username."'";
		    return DB::update($this->_table,$data,$condition,$unbuffered,$low_priority);
		}else{
			return false;
		}
		
	}
	public function insert($data,$return_insert_id=false,$replace=false,$silent=false){
		if($data && is_array($data)){
			return DB::insert($this->_table, $data, true);
		}
		return false;
	}
	public function delete_by_uid($uid){
		$uid=intval($uid);
		if(!empty($uid) && $uid!=0){
			return DB::delete($this->_table, array('uid'=>$uid));
		}
		return false;
	}
	public function fetch_all_by_uid($uid){
		if(!empty($uid)){
			$uid=intval($uid);
			return DB::fetch_all('SELECT * FROM %t WHERE uid=%d',array($this->_table,$uid));//返回数组包含各个字段的值
		}
		return false;
	}
	public function update_by_uid($uid,$data,$unbuffered = false, $low_priority = false){
		if(!empty($uid) && !empty($data)){
			$condition=$this->_pk."='".$uid."'";
			return DB::update($this->_table,$data,$condition,$unbuffered,$low_priority);//返回前一次 MySQL 操作所影响的记录行数
		}
		return false;
	}
	public function update_checkcount_by_uid($uid){
		if(!empty($uid)){
			return DB::query('UPDATE %t SET `checkcount`=`checkcount`+1 WHERE uid=%d', array($this->_table, $uid));
		}
	}
	public function fecth_like_username($username,$limit){
		if(empty($username)){
			return DB::fecth_all("SECLET username FROM %t LIMIT %d",array($this->_table,$limit));
		}else{
			return DB::fecth_all("SECLET username FROM %t WHERE username LIKE %s LIMIT %d",array($this->_table,$username."%",$limit));
		}
	}
}
?>